﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentProject.Model;
using System.Data.SqlClient;
using System.Data;

namespace StudentProject.DAL
{
    public class StudentServiceDal
    {

        /// <summary>
        /// 查询数据库
        /// 这里查询的是试图
        /// </summary>
        /// <returns></returns>
        public List<View_StudentClass> GetListStudent()
        {
            string sql = "select * from View_StudentClass";
            //使用helper进行查询，得到结果
            DataTable dt = SqlHelper.ExecuteDataTable(sql);

            //将dt中的数据转存到list中
            List<View_StudentClass> list = new List<View_StudentClass>();
            foreach (DataRow row in dt.Rows)
            {
                list.Add(new View_StudentClass()
                {
                    ID = row["ID"].ToString(),
                    SName = row["SName"].ToString(),
                    Sex = row["Sex"].ToString(),
                    Birthday = Convert.ToDateTime(row["Birthday"].ToString()),
                    Policy = row["Policy"].ToString(),
                    Nation = row["Nation"].ToString(),
                    IDCard = row["IDCard"].ToString(),
                    CName = row["CName"].ToString(),
                    Memo = row["Memo"].ToString()
                });
            }
            //将集合返回
            return list;
        }



    }
}
